clear;clc;
load('D:\Ralph\ECoG\Van Dora\ctmr\dj\jans_electrodes_surface_loc_all1.mat');
labels = ...
    { 'T01'    'T02'    'T03'    'T04'    'T05'    'T06'    'T07'    'T08'    'T09'    'T10'    'T11'    'T12'    'T13'    'T14'    'T15'    'T16'    'T17' ...
    'T18'    'T19'    'T20'    'T21'    'T22'    'T23'    'T24'    'T25'    'T26'    'T27'    'T28'    'T29'    'T30'    'T31'    'T32'    'Oc01'    'Oc02' ...
    'Oc03'    'Oc04'    'Oc05'    'Oc06'    'Oc07'    'Oc08'    'Oc09'    'Oc10'    'Oc11'    'Oc12'    'Oc13'    'Oc14'    'Oc15'    'Oc16'    'sT1'    'sT2'  ...
    'sT3'    'sT4'    'sT5'    'sT6'    'sT7'    'sT8'    'sO1'    'sO2'    'sO3'    'sO4'    'sO5'    'sO6'    'sO7'    'sO8'    'OL01'    'OL02'    'OL03' ...
    'OL04'    'OL05'    'OL06'    'OL07'    'OL08'    'OL09'    'OL10'    'OL11'    'OL12'    'OL13'    'OL14'    'OL15'    'OL16'    'PO1'    'PO2'    'PO3' ...
    'PO4'    'PO5'    'PO6'    'PO7'    'PO8'    'PO9'    'PO10'    'PO11'    'PO12'    'PO13'    'PO14'    'PO15'    'PO16'    'TO01'    'TO02'    'TO03' ...
    'TO04'    'TO05'    'TO06'    'TO07'    'TO08'    'TO09'    'TO10'    'TO11'    'TO12'    'TO13'    'TO14'    'TO15'    'TO16'    'C01'    'C02'    'C03' ...
    'C04'    'C05'    'C06'    'C07'    'C08'    'R1+'    'R2+'    'R3+'    'R4+'    'kin+'    'orb+'    'ECG+'    'AH+' ...
    }';

fid = fopen('TestDJ.xyz', 'wt');
for i = 1:length(labels)
    C.Name = labels{i};
    if i<size(elecmatrix,1)
    C.x = elecmatrix(i,1);
    C.y = elecmatrix(i,2);
    C.z = elecmatrix(i,3);
    else
    C.x = 0;
    C.y = 0;
    C.z = 0;
    end        
    fprintf(fid, '%i \t%3.2f \t%3.2f \t%3.2f \t%s\n', i, ...
        C.x, ...
        C.y, ...
        C.z, ...
        C.Name);
end
fclose(fid);











return;

%% Load labels and locations into EEG set
presetXyz.FROA.x    = -0.30; presetXyz.FROA.y    =  0.15; presetXyz.FROA.z    =  0.40;
presetXyz.FROP.x    = -0.05; presetXyz.FROP.y    = -0.07; presetXyz.FROP.z    =  0.50;
presetXyz.PARA.x    = -0.40; presetXyz.PARA.y    = -0.10; presetXyz.PARA.z    =  0.35;
presetXyz.PARO.x    = -0.15; presetXyz.PARO.y    = -0.40; presetXyz.PARO.z    =  0.10;
presetXyz.IPSS.x    = -0.10; presetXyz.IPSS.y    = -0.20; presetXyz.IPSS.z    =  0.34;
presetXyz.IPSI.x    = -0.30; presetXyz.IPSI.y    = -0.17; presetXyz.IPSI.z    =  0.15;
presetXyz.IPS.x     = -0.20; presetXyz.IPS.y     = -0.18; presetXyz.IPS.z     =  0.25;
presetXyz.TEMS.x    = -0.75; presetXyz.TEMS.y    = -0.15; presetXyz.TEMS.z    = -0.20;
presetXyz.TEMM.x    = -0.80; presetXyz.TEMM.y    = -0.20; presetXyz.TEMM.z    = -0.35;
presetXyz.TEMI.x    = -0.85; presetXyz.TEMI.y    = -0.25; presetXyz.TEMI.z    = -0.45;
presetXyz.OCCD.x    = -0.30; presetXyz.OCCD.y    = -0.50; presetXyz.OCCD.z    = -0.10;
presetXyz.OCCV.x    = -0.40; presetXyz.OCCV.y    = -0.60; presetXyz.OCCV.z    = -0.30;
presetXyz.TEM.x     = -0.80; presetXyz.TEM.y     = -0.20; presetXyz.TEM.z     = -0.33;
presetXyz.OCC.x     = -0.35; presetXyz.OCC.y     = -0.50; presetXyz.OCC.z     = -0.20;
presetXyz.m1OCCV.x  = -0.40; presetXyz.m1OCCV.y  = -0.60; presetXyz.m1OCCV.z  = -0.10;
presetXyz.m1OCCD.x  = -0.30; presetXyz.m1OCCD.y  = -0.50; presetXyz.m1OCCD.z  = -0.10;
presetXyz.m1TEM.x   = -0.80; presetXyz.m1TEM.y   = -0.20; presetXyz.m1TEM.z   = -0.33;
presetXyz.m1IPSS.x  = -0.10; presetXyz.m1IPSS.y  = -0.20; presetXyz.m1IPSS.z  =  0.34;
presetXyz.m1Motor.x =  0.00; presetXyz.m1Motor.y =  0.00; presetXyz.m1Motor.z =  0.00;
fid = fopen('Regions.xyz', 'wt');
for r = 1:length(chandefs)
    fprintf(fid, '%i \t%3.2f \t%3.2f \t%3.2f \t%s\n', r, ...
        presetXyz.(chandefs(r).Name).x, ...
        presetXyz.(chandefs(r).Name).x, ...
        presetXyz.(chandefs(r).Name).x, ...
        chandefs(r).Name);
end
fclose(fid);
NEWEEG = pop_chanedit(NEWEEG,  'load', {'Regions.xyz', 'filetype', 'xyz'});
NEWEEG = eeg_checkset(NEWEEG);